<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>后台管理</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="icon" href="__PUBLIC__/images/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="__ADMIN__/plugins/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="__ADMIN__/css/global.css" media="all">
<link rel="stylesheet" href="__ADMIN__/plugins/font-awesome/css/font-awesome.min.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
<include file="Common:header" />
<!-- 左边菜单 -->
<div class="layui-side layui-bg-black">
<div class="layui-side-scroll">
<ul class="layui-nav layui-nav-tree admin-nav-tree">
						<foreach name="menus" item="v">
						<!--  layui-nav-itemed -->
						<li class="layui-nav-item">
							<a href="javascript:;">{$v.title}</a>
							<dl class="layui-nav-child">
								<foreach name="v[$v['id']]" item="val">
								<dd>
									<a href="javascript:;" data-url="{:U($val['menu_name'])}">
										<i class="layui-icon" style="top: 1px; font-size: 18px;">{:html_entity_decode($val['icon'])}</i>
										<cite>{$val.title}</cite>
									</a>
								</dd>
								</foreach>
							</dl>
						</li>
						</foreach>
					</ul>
				</div>
			</div>
			<!-- 左边菜单 -->
			<div class="layui-body" style="bottom: 0;">
				<div class="layui-tab admin-nav-card" lay-filter="admin-tab">
					<ul class="layui-tab-title" id="admin-tab">
						<li class="layui-this">
							<i class="layui-icon" style="top: 2px; font-size: 16px;">&#xe609;</i>
							<cite>控制台</cite>
						</li>
					</ul>
					<div class="layui-tab-content" style="min-height: 150px; padding: 5px 0 0 0;" id="admin-tab-container">
						<div class="layui-tab-item layui-show">
							<iframe src="{:U('Index/main')}"></iframe>
						</div>
					</div>
				</div>
			</div>
			<div class="layui-footer footer footer-demo">
				<div class="layui-main">
					<p>2016 &copy;
						<a href="#here">管理后台</a>
					</p>
				</div>
			</div>
			<div class="site-tree-mobile layui-hide">
				<i class="layui-icon">&#xe602;</i>
			</div>
<div class="site-mobile-shade"></div>
</div>
</body>
<script type="text/javascript" src="__ADMIN__/plugins/layui/layui.js"></script>
<script>
layui.use(['element', 'layer'], function() {
    var element = layui.element(),
    $ = layui.jquery,
    layer = layui.layer;
    //iframe自适应
    $(window).on('resize', function() {
        var $content = $('.admin-nav-card .layui-tab-content');
        $content.height($(this).height() - 147);
        $content.find('iframe').each(function() {
            $(this).height($content.height());
        });
    }).resize();
    //添加tab
    var $tabs      = $('#admin-tab');
    var $container = $('#admin-tab-container');
    $(document).delegate('#loginUserInfo', 'click',function(){
        var url = "{:U('Index/edit')}";
        $.get(url,function(data){
        if(data.status == 'error'){
            layer.msg(data.msg,{icon: 5});
            return;
        }
        layer.open({
            title:'个人信息',
            type: 1,
            id:'modifypersoninfo',
            skin: 'layui-layer-rim', //加上边框
            area: ['500px','500px'], //宽高
            content: data,
        });
	})
    });
    //绑定 nav 点击事件
    $('ul.admin-nav-tree').find('dd > a').each(function() {
        var $this = $(this);
        //获取设定的url
        var url = $this.data('url');
        if(url !== undefined) {
            $this.on('click', function() {
            var iframe = '<iframe src="' + url + '"></iframe>';
            var aHtml = $this.html();
            var count = 0;
            var tabIndex;
            $tabs.find('li').each(function(i, e) {
                var $cite = $(this).children('cite');
                if($cite.text() === $this.find('cite').text()) {
                    count++;
                    tabIndex = i;
                };
            });
            //tab不存在
            if(count === 0) {
                //添加删除样式
                aHtml += '<i class="layui-icon layui-unselect layui-tab-close">&#x1006;</i>';
		//添加tab
		element.tabAdd('admin-tab', {
                    title: aHtml,
                    content: iframe
		});
		//iframe 自适应
		var $content = $('.admin-nav-card .layui-tab-content');
		$content.find('iframe').each(function() {
                    $(this).height($content.height());
                });
                //绑定关闭事件
		$tabs = $('#admin-tab');
		var $li = $tabs.find('li');
		$li.eq($li.length - 1).children('i.layui-tab-close').on('click', function() {
                    element.tabDelete('admin-tab', $(this).parent('li').index()).init();
		});
		//获取焦点
		element.tabChange('admin-tab', $li.length - 1);
            } else {
                //切换tab
                element.tabChange('admin-tab', tabIndex);
            }
            });
        }
    });
    $('#user').on('click', function() {
        $('#user-item').toggle();
    });
    //手机设备的简单适配
    var treeMobile = $('.site-tree-mobile'),
    shadeMobile = $('.site-mobile-shade');
    treeMobile.on('click', function() {
        $('body').addClass('site-mobile');
    });
    shadeMobile.on('click', function() {
        $('body').removeClass('site-mobile');
    });
});
</script>
</html>
